<?php 

class Admin_OrderController extends Zend_Controller_Action{

	const PERMISSION_DENIED = 1;
	const RESULT_NOT_FOUND = 2;
		
	protected $_searchQuery;
	
	public function init()
	{
		$this->_searchQuery = new Admin_Model_Orders();
	}
	
	public function indexAction(){

		$itemCountPerPage = 10;
		
		$form = new Admin_Form_SearchOrder(array(
			'action'	=>	'/admin/order',
			'method'	=>	'post'
		));
		
		$request = $this->getRequest();
		if($request->isPost()){
			$this->_searchQuery->create($request->getPost());
			$itemCountPerPage = $request->getPost('itemCountPerPage');
		}
		//var_dump($this->_searchQuery->getQuery());
        $this->view->form = $form;		
		/**
         * Paginator
         */
        if($this->_searchQuery->getQuery()){
	        $adapter = new Custom_Paginator_Adapter_Doctrine($this->_searchQuery->getQuery());
	        
	        $paginator = new Zend_Paginator( $adapter );
	        $paginator->setItemCountPerPage( $itemCountPerPage )
	                  ->setCurrentPageNumber( $this->_getParam( 'page', 1 ) )
	                  ->setPageRange( 8 );
			//var_dump($paginator);
	        $this->view->paginator = $paginator;
        }
		
	}
	
	public function detailAction(){
		$request = $this->getRequest();
		
		$this->view->orderId = $request->orderId;
		
		$this->view->orderForm = new Admin_Form_OrderAdjustment();
		$this->view->itemForm = new Admin_Form_ItemAdjustment();
		$this->view->rejectForm = new Admin_Form_ItemReject();		
	}
}